package com.hucheng.goods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.hucheng.common.page.CommonPager;
import com.hucheng.common.page.PageParameter;
import com.hucheng.goods.mapper.GoodsMapper;
import com.hucheng.goods.query.GoodsQuery;
import com.hucheng.goods.service.GoodsService;
import com.hucheng.goods.vo.GoodsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.stream.Collectors;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-06-25
 * @Description: 商品逻辑实现类
 **/
@Component
@Service(interfaceClass = GoodsService.class, retries = -1, timeout = 5000)
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public CommonPager<GoodsVO> listByPage(GoodsQuery goodsQuery) {
        return new CommonPager<>(
                new PageParameter(goodsQuery.getPageParameter().getCurrentPage()
                ,goodsQuery.getPageParameter().getPageSize(),
                        goodsMapper.countByQuery(goodsQuery)),
                goodsMapper.selectByQuery(goodsQuery).stream().map(GoodsVO::buildGoodsVO).collect(Collectors.toList()));
    }
}
